<template>
  <div class="waiting-info">
    <div class="list-item-setting">
      <div class="title-info">
        <el-divider content-position="left">区域设置</el-divider>
      </div>
      <el-form-item label="展示列数">
        <el-input-number
            :min="4"
            :max="optionsInfo?.maxRow || 5"
            v-model="optionsInfo.showRowNums"
            class="hide-spin-button"
            size="small"
            @change="handleTotal"
        />
      </el-form-item>
      <el-form-item label="内容高度">
        <el-input-number
            v-model="optionsInfo.contentHeight"
            :min="0"
            size="small"
            class="hide-spin-button"
        />
      </el-form-item>
    </div>
    <div class="list-title-setting">
      <div class="title-info">
        <el-divider content-position="left">列表设置</el-divider>
      </div>
      <el-form-item label="患者诊室名" v-if="fieldHas('patientRoomNameKey')" class="column-info">
        <el-select v-model="optionsInfo['patientRoomNameKey']" placeholder="请选择">
          <el-option
              v-for="item in roomOptions2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>

      </el-form-item>

      <!--诊室Key-->
      <template v-if="optionsInfo.queueName==='roomName'">
        <RoomNameKeyEditor
            businessType="special"
            :designer="designer"
            :selected-widget="selectedWidget"
            :option-model="optionModel"
        />
      </template>

      <!--号别Key-->
      <template v-if="optionsInfo.queueName==='registerName'">
        <el-form-item label="队列号别名称" class="column-info">
          <el-select v-model="optionsInfo['registerNameKey']" placeholder="请选择">
            <el-option
                v-for="item in registerOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            />
          </el-select>
        </el-form-item>
      </template>

      <el-form-item label="背景颜色">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo.headerBackgroundColor"/>
      </el-form-item>

      <el-form-item label="字体颜色">
        <el-color-picker
            size="small"
            show-alpha
            :predefine="predefineColors"
            v-model="optionsInfo.headerFontColor"/>
      </el-form-item>
      <el-form-item label="切屏时间(s)">
        <el-input-number
            :min="10"
            :step="1"
            v-model="optionsInfo.switchTime"
            :disabled="!(optionsInfo.switchScreen)"
            size="small"
            class="hide-spin-button"
        />
      </el-form-item>
    </div>


    <!--等待就诊滚动设置-->
    <div class="wait-visit-setting">
      <div class="title-info">
        <el-divider content-position="left">等待就诊</el-divider>
      </div>

      <el-form-item label="患者号标识颜色" class="column-info">
        <el-switch v-model="optionsInfo.orderTag"/>
        <el-tooltip class="item" effect="dark" content="颜色需要在规则中配置，如果规则中无此配置，即使打开该配置依旧无效"
                    placement="bottom">
          <el-button>
            <i class="el-icon-warning"></i>
          </el-button>
        </el-tooltip>
      </el-form-item>

      <el-form-item label="患者字号">
        <el-input-number
            size="small"
            v-model="optionsInfo.patientFontSize"
        />
      </el-form-item>

      <el-form-item label="开启滚动">
        <el-switch v-model="optionsInfo.openScroll"/>
      </el-form-item>

      <el-form-item label="视图首屏数量" class="column-info">
        <el-input-number
            size="small"
            :min="optionsInfo.viewMinNumber || 4"
            :max="optionsInfo.viewManNumber || 4"
            v-model="optionsInfo.viewNumber"
        />
      </el-form-item>

      <el-form-item label="开启滚动数量" class="column-info">
        <el-input-number
            :min="0"
            size="small"
            class="hide-spin-button"
            v-model="optionsInfo.waitingNumber"
        />
      </el-form-item>

      <el-form-item label="滚动速度" class="column-info">
        <el-input-number
            :min="1"
            :max="5"
            size="small"
            class="hide-spin-button"
            :disabled="!(optionsInfo.openScroll)"
            v-model="optionsInfo.waitingVisitStep"
        />
      </el-form-item>
    </div>
  </div>
</template>

<script>
import Draggable from "vuedraggable"
import constantDic from "@/utils/vue-i18n/lang/zh-CN";
import RoomNameKeyEditor from "../basicInfo/roomNameKey-editor.vue";
import QueueRoomOptions from "../basicInfo/queueRoomOptions-editor.vue";
import * as types from "@c/public/form-designer/devType/datas-types";
import {queueRoomOptions, registerOptions, roomOptions2} from "@c/public/form-designer/devType/datas-types";

export default {
  name: "sceneWaitRowConfig-editor",

  componentName: "sceneWaitRowConfig-editor",

  components: {
    Draggable,
    RoomNameKeyEditor,
    QueueRoomOptions,
  },

  mixins: [],

  props: {
    designer: Object,
    selectedWidget: Object,
    optionModel: Object,
  },

  inject: ['serverFieldList', 'getDesignerConfig'],

  data() {
    return {
      constantDic: constantDic,
      optionsInfo: Object(),
      predefineColors: types['predefineColors'],
      queueRoomOptions: types['queueRoomOptions'],
      registerOptions: types['registerOptions'],
      roomOptions2: types['roomOptions2']
    }
  },

  computed: {
    fieldHas() {
      return function (field) {
        return Reflect.has(this.optionsInfo, field)
      }
    },
  },

  methods: {
    // 获取队列的长度
    handleTotal(val) {
      let {multiple} = (this.optionsInfo);
      Reflect.set(this.optionsInfo, 'rowNumber', multiple * val)
    }
  },

  watch: {
    // 组件的所有信息
    optionModel: {
      handler: function (val) {
        let key = (val.config)
        this.optionsInfo = val[key];
      },
      deep: true,
      immediate: true
    }
  }

}
</script>

<style lang="scss" scoped>
.col-info {
  :deep(.el-form-item__content) {
    margin-left: 1px !important;

    .title {
      width: 100%;
    }

    .el-checkbox__label {
      width: 100%;
    }

    .el-checkbox {
      width: calc(100% - 32px);
    }
  }
}

.column-info {
  display: flex;
  flex-direction: column;

  :deep(.el-form-item__label) {
    width: 100% !important;
  }

  :deep(.el-form-item__content) {
    width: 100% !important;
    margin-left: 0 !important;

    .el-button {
      color: #e58602;
      font-size: 18px;
      flex-shrink: 0;
      padding: 0 15px;
      border-color: transparent !important;
      background: transparent !important;
    }

    .el-select {
      width: 100% !important;
    }
  }
}

</style>